package com.sunchen.asc.service.item.repository;

import com.sunchen.asc.service.item.domain.Material;
import com.sunchen.asc.service.item.vo.MaterialVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface MaterialRepository extends JpaRepository<Material,Long> {

    @Modifying
    @Query("delete from Material t where t.itemId = ?1")
    void deleteAllByItemId(Long itemId);

    @Query("select new com.sunchen.asc.service.item.vo.MaterialVo(t.id,t.itemId,t.name,t.type,t.url,t.fileName,t.sortOrder,t.remark,t.businessType,t.documentFormat,t.fillingExplanation,t.acceptStandard,t.sortCode,t.origin,t.copy,t.must,t.flag,t.catalogCode,t.how,t.what,t.wherever,t.publisher,t.publishTime,t.sample,t.sampleName,t.blank,t.blankName,t.paperStandar,t.original,t.isElectronic,t.materialBasis) from Material t where t.itemId = ?1 order by t.sortOrder asc")
    List<MaterialVo> getVosByItemId(Long itemId);
}
